@page "/Gateway/Gateway"
@using BlazorApp.Pages.Common
@using BlazorApp.Pages.Common.Html.HTable
@using BlazorApp.Pages.Common.Metadata
@using BlazorApp.Utils
@using Entity.Crd.Gateway
@using k8s.Models
@using Mapster
@inherits BlazorApp.Pages.Common.TableBase<Entity.Crd.Gateway.V1Gateway>
@if (TableData.PagedItems != null)
{
    <HTable Class="wideTable">
        <HTr>
            <HTd>
                <SearchToolBar Title=@L["Gateway"] Count="@TableData.Total"
                               OnItemDeletedCallback="@(async () => await InvokeAsync(StateHasChanged))"
                               OnSelectedItemCloseClicked="@TableData.RemoveSelection"
                               OnRemoveAllClicked="@TableData.RemoveAllSelection" TableData="@TableData"
                               OnSearch="OnSearchHandler" TItem="V1Gateway"
                               OnNsSelected="OnNsSelectedHandler">
                </SearchToolBar>
            </HTd>
        </HTr>
        <HTr>
            <HTd>
                <Table TItem="V1Gateway"
                       DataSource="@TableData.PagedItems"
                       Size=@TableSize.Small Bordered="true"
                       Total="TableData.Total"
                       @bind-PageIndex="TableData.PageIndex"
                       @bind-PageSize="TableData.PageSize"
                       @bind-SelectedRows="TableData.SelectedRows"
                       Loading="TableData.Loading"
                       OnChange="OnPageChangeHandler">
                    <Selection Key="@(context.Name())"/>
                    <AntDesign.Column Field="@context.Name()" Title="@L["Name"]">
                        <Button OnClick="@(() => OnItemNameClick(context))" Type="@ButtonType.Link">@context.Name()</Button>
                    </AntDesign.Column>
                    <AntDesign.Column Field="@context.Namespace()" Title="@L["Namespace"]" Width="110px"/>

                    <AntDesign.Column Title=@L["GatewayClassName"] TData="string" Width="150px">
                        <RefView OnlyName
                                 Ref="@KubeHelper.GetObjectRef("GatewayClass", context.Spec.GatewayClassName)">
                        </RefView>
                    </AntDesign.Column>


                    <AntDesign.Column Title=@L["Addresses"] TData="string" Width="200px">
                        @if (context.Status.Addresses is { Count: > 0 })
                        {
                            foreach (var address in context.Status.Addresses)
                            {
                                <ColorfulTag>@address.Value</ColorfulTag>
                            }
                        }

                    </AntDesign.Column>
                    <AntDesign.Column Title=@L["Listener"] TData="string" Width="600px">
                        <ListenerStatusView Status="@context.Status.Listeners"></ListenerStatusView>
                    </AntDesign.Column>
                    <AntDesign.Column Title=@L["Condition"] TData="string" Width="150px">
                        <ConditionsTagView
                            Conditions="@(context.Status.Conditions.Adapt<IList<V1Condition>>())">
                        </ConditionsTagView>
                    </AntDesign.Column>
                    <AntDesign.Column Title="@L["Age"]" TData="string" Width="100px">
                        <AgeView Age="@context.CreationTimestamp()"></AgeView>
                    </AntDesign.Column>
                    <ActionColumn Title="@L["Action"]" Width="100px">
                        <GatewayAction Item="@context"></GatewayAction>
                    </ActionColumn>
                </Table>
            </HTd>
        </HTr>
    </HTable>
    <ResourceWatcher OnResourceChanged="OnResourceChanged" T="V1Gateway"></ResourceWatcher>
}
